package com.dr.cmdb.core.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author rui.duan
 * @version 1.0
 * @className FiledCheckEnum
 * @description 操作类型
 * @date 2021-03-29 11:39
 */
@Getter
@AllArgsConstructor
public enum OperateTypeEnum {
    /**
     * 模型日志
     */
    ADD(0,"新增"),

    DELETE(1,"删除"),

    MODIFY(2,"修改"),

    IMPORT(3,"导入"),
    EXPORT(4, "导出"),
    OTHER(5,"其他")
    ;


    private Integer code;
    private String value;
    

    /**
     * 根据code获取值
     * @param code
     * @return
     */
    public static String getValueByCode(Integer code) {
        OperateTypeEnum[] values = OperateTypeEnum.values();
        for (OperateTypeEnum type : values) {
            if (type.code.equals(code)) {
                return type.value;
            }
        }
        return null;
    }

    public static List<Integer> getCodes() {
        List<Integer> codes = Lists.newArrayList();
        OperateTypeEnum[] values = OperateTypeEnum.values();
        for (OperateTypeEnum type : values) {
            codes.add(type.getCode());
        }
        return codes;
    }

    /**
     * 根据value获取code
     * @param value
     * @return
     */
    public static Integer getCodeByValue(String value) {
        OperateTypeEnum[] values = OperateTypeEnum.values();
        for (OperateTypeEnum type : values) {
            if (type.value.equalsIgnoreCase(value)) {
                return type.code;
            }
        }
        return null;
    }
}
